﻿using System;
using System.IO;
using System.Web.Hosting;

namespace Toast.Core
{
    public abstract class FileMatcher
    {
        readonly string _path;
        readonly string _physicalPath;

        protected FileMatcher(string path)
        {
            _path = path;
            _physicalPath = HostingEnvironment.MapPath(Path.GetDirectoryName(_path));
            if (!IsValid) throw new ArgumentException("Supplied path is invalid");
        }

        public string VirtualDirectory
        {
            get { return Path.GetDirectoryName(_path); }
        }

        public string PhysicalDirectory
        {
            get { return _physicalPath; }
        }

        public string SearchPattern
        {
            get { return Path.GetFileName(_path); }
        }

        bool IsValid
        {
            get { return Path.IsPathRooted(_physicalPath) && Path.HasExtension(_path) && Directory.Exists(PhysicalDirectory); }
        }

        public abstract string[] GetMatchingFiles();
    }
}